package com.nbjtjc.safe.service.cost;

import cn.hutool.core.util.ObjectUtil;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.cost.CostBudgetItem2Mapper;
import com.nbjtjc.safe.mapper.cost.CostBudgetPlanMapper;
import com.nbjtjc.safe.model.cost.CostBudgetItem2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CostBudgetItem2Service {
	@Autowired
	private CostBudgetItem2Mapper costBudgetItem2Mapper;
//	@Autowired
//	private CostBudgetPlan costBudgetPlan;
	@Autowired
	private CostBudgetPlanMapper costBudgetPlanMapper;
	
	public Result add(CostBudgetItem2 costBudgetItem2){
		Result result = new Result();
		int res=-1;
		if(ObjectUtil.isNull(costBudgetItem2)||ObjectUtil.isNull(costBudgetItem2.getBudgetPlanId())){
			result.setFalse("项目不能为空，关联预算计划不能为空");
			return result;
		}
		res= costBudgetItem2Mapper.insertSelective(costBudgetItem2);
		if(res==0){
			result.setFalse("新增预算项目失败");
			return result;
		}
		
		result.setData(costBudgetItem2);
		return result;
	}
	
	public Result update(CostBudgetItem2 costBudgetItem2){
		Result result = new Result();
		int res=-1;
		if(ObjectUtil.isNull(costBudgetItem2)||ObjectUtil.isNull(costBudgetItem2.getId())||ObjectUtil.isNull(costBudgetItem2.getBudgetPlanId())){
			result.setFalse("项目不能为空，项目ID不能为空，关联预算计划不能为空");
			return result;
		}
		res= costBudgetItem2Mapper.updateByPrimaryKeySelective(costBudgetItem2);
		if(res==0){
			result.setFalse("更新预算项目失败");
			return result;
		}
		
		result.setData(costBudgetItem2);
		return result;
	}
	
//	public Result find(CostBudgetItem2 costBudgetItem2){
//		Result result = new Result();
//	    PageHelper.startPage(costBudgetItem2.getPageCurrent(), costBudgetItem2.getPageSize());
//		List<CostBudgetItem2> costBudgetItem2s= costBudgetItem2Mapper.search(costBudgetItem2);
//	    result.setData(new PageInfo<>(costBudgetItem2s));
//		return result;
//	}
	
	public Result show(int id){
		Result result = new Result();
		CostBudgetItem2 costBudgetItem2 = costBudgetItem2Mapper.selectByPrimaryKey(id);
		
		result.setData(costBudgetItem2);
		return result;
	}
	
	public Result delete(CostBudgetItem2 costBudgetItem2){
		Result result = new Result();
		if(ObjectUtil.isNull(costBudgetItem2)||ObjectUtil.isNull(costBudgetItem2.getId())){
			result.setFalse("删除项目和项目ID不能为空");
			return result;
		}
		costBudgetItem2.setCancel(1);
		int res= costBudgetItem2Mapper.updateByPrimaryKeySelective(costBudgetItem2);
		if(res==0){
			result.setFalse("删除预算项目失败");
			return result;
		}
		result.setData(costBudgetItem2);
		return result;
	}
}
